home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / lib / udev / hdparm < prev    next >
Text File  |  2008-06-19  |  6KB  |  246 lines

  1. #!/bin/sh
  2.  
  3. set -e
  4.  
  5. [ "$DEVNAME" ] || exit 1
  6.  
  7. if [ -e /proc/cmdline ]; then #linux only - future proofing against BSD and Hurd :)
  8.   if grep -wq "nohdparm" /proc/cmdline ; then
  9.     exit 0
  10.   fi
  11. fi
  12.  
  13. raidstat=OK
  14. if [ -e /proc/mdstat ]; then
  15.   if egrep -iq "resync|repair|recover|check" /proc/mdstat; then
  16.     raidstat=RESYNC
  17.   fi
  18. elif [ -e /proc/rd/status ]; then
  19.   raidstat=`cat /proc/rd/status`
  20. fi
  21.  
  22. if ! [ "$raidstat" = 'OK' ]; then
  23.   exit 1
  24. fi
  25.  
  26. set_option()
  27. {
  28.   if test -n "$DISC"; then
  29.     NEW_OPT=
  30.     for i in $OPTIONS; do
  31.       if test x${i%${i#??}} != x${1%${1#??}}; then
  32.         NEW_OPT="$NEW_OPT $i"
  33.       else
  34.         NEW_OPT=${NEW_OPT%-q}
  35.       fi
  36.     done
  37.     OPTIONS="$NEW_OPT $OPT_QUIET $1"
  38.   else
  39.     NEW_DEF=
  40.     for i in $DEFAULT; do
  41.       if test x${i%${i#??}} != x${1%${1#??}}; then
  42.         NEW_DEF="$NEW_DEF $i"
  43.       else
  44.         NEW_DEF=${NEW_DEF%-q}
  45.       fi
  46.     done
  47.     DEFAULT="$NEW_DEF $DEF_QUIET $1"
  48.   fi
  49. }
  50.  
  51. eval_value()
  52. {
  53.   case $1 in
  54.     off|0)
  55.       set_option "$2"0
  56.        ;;
  57.     on|1)
  58.       set_option "$2"1
  59.       ;;
  60.     *)
  61.       log_failure_msg "Unknown Value for $2: $1"
  62.       exit 1
  63.       ;;
  64.   esac
  65. }
  66.  
  67. WAS_RUN=0
  68.  
  69. # Get blocks as far as the drive's write cache.
  70. /bin/sync
  71.  
  72. DISC=
  73. DEFAULT=
  74. OPTIONS=
  75. DEF_QUIET=
  76. OPT_QUIET=
  77.  
  78. egrep -v '^[[:space:]]*(#|$)' /etc/hdparm.conf | 
  79. {
  80.   while read KEY SEP VALUE; do
  81.     if [ "$NEXT_LINE" != 'go' ]; then
  82.       case $SEP in
  83.         '{')
  84.           case $KEY in
  85.             command_line)
  86.               NEXT_LINE=go
  87.               unset DISC
  88.               unset OPTIONS
  89.               unset OPT_QUIET
  90.               IN_BLOCK=0
  91.               ;;
  92.             *)
  93.               DISC=$KEY
  94.               OPTIONS=$DEFAULT
  95.               OPT_QUIET=$DEF_QUIET
  96.               WAS_RUN=0
  97.               if [ "$DISC" = "$DEVNAME" ]; then
  98.                 IN_BLOCK=1
  99.               else
  100.                 IN_BLOCK=0
  101.               fi
  102.               ;;
  103.           esac
  104.           ;;
  105.         =)
  106.           case $KEY in
  107.             read_ahead_sect) 
  108.               set_option -a$VALUE
  109.               ;;
  110.             lookahead) 
  111.               eval_value $VALUE -A
  112.               ;;
  113.             bus) 
  114.               eval_value $VALUE -b
  115.               ;;
  116.             apm) 
  117.               set_option -B$VALUE
  118.               ;;
  119.             io32_support) 
  120.               set_option -c$VALUE
  121.               ;;
  122.             dma) 
  123.               eval_value $VALUE -d
  124.               ;;
  125.             defect_mana) 
  126.               eval_value $VALUE -D
  127.               ;;
  128.             cd_speed) 
  129.               set_option -E$VALUE
  130.               ;;
  131.             mult_sect_io) 
  132.               set_option -m$VALUE
  133.               ;;
  134.             prefetch_sect) 
  135.               set_option -P$VALUE
  136.               ;;
  137.             read_only) 
  138.               eval_value $VALUE -r
  139.               ;;
  140.             spindown_time) 
  141.               set_option -S$VALUE
  142.               ;;
  143.             poweron_standby) 
  144.               eval_value $VALUE -s
  145.               ;;
  146.             interrupt_unmask) 
  147.               eval_value $VALUE -u
  148.               ;;
  149.             write_cache) 
  150.               eval_value $VALUE -W
  151.               ;;
  152.             transfer_mode) 
  153.               set_option -X$VALUE
  154.               ;;
  155.             acoustic_management)
  156.               set_option -M$VALUE
  157.               ;;
  158.             keep_settings_over_reset)
  159.               eval_value $VALUE -k
  160.              ;;
  161.             keep_features_over_reset)
  162.               eval_value $VALUE -K
  163.              ;;
  164.             chipset_pio_mode)
  165.               set_option -p$VALUE
  166.              ;;
  167.             security_unlock)
  168.               set_option --security-unlock $VALUE
  169.              ;;
  170.             security_pass)
  171.               set_option --security-set-pass $VALUE
  172.              ;;
  173.             security_disable)
  174.               set_option --security-disable $VALUE
  175.              ;;
  176.             user-master)
  177.               set_option --user-master $VALUE
  178.               ;;
  179.             security_mode)
  180.               set_option --security-mode $VALUE
  181.              ;;
  182.             ROOTFS)
  183.               ROOTFS=$VALUE
  184.              ;; 
  185.             *)
  186.               echo "Unknown option $KEY"
  187.               exit 1
  188.               ;;
  189.           esac
  190.           ;;
  191.         "")
  192.           case $KEY in
  193.             '}')
  194.               if [ -z "$DISC" ] && [ "$WAS_RUN" != '1' ]; then
  195.         echo "No disk enabled. Exiting"
  196.                 exit 1
  197.               fi
  198.               if [ -n "$OPTIONS" ] && [ -b "$DISC" ]; then
  199.                 ret=0
  200.                 if [ "$IN_BLOCK" = 1 ]; then
  201.                   # Flush the drive's internal write cache to the disk.
  202.                   /sbin/hdparm -q -f $DISC 2>/dev/null || ret=$?
  203.                   /sbin/hdparm $OPTIONS $DISC 2>/dev/null || ret=$?
  204.                 fi
  205.               fi       
  206.               ;;
  207.             quiet)
  208.               if [ -n "$DISC" ]; then
  209.                 OPT_QUIET=-q
  210.               else
  211.                 DEF_QUIET=-q
  212.               fi
  213.               ;;
  214.             standby) 
  215.               set_option -y
  216.               ;;
  217.             sleep) 
  218.               set_option -Y
  219.               ;;
  220.             disable_seagate) 
  221.               set_option -Z
  222.               ;;
  223.             security_freeze) 
  224.               set_option --security-freeze
  225.               ;;
  226.             *)
  227.               echo "unknown option $KEY"
  228.               exit 1
  229.               ;;
  230.           esac
  231.           ;;
  232.        *)
  233.          echo "unknown separator $SEP"
  234.          exit 1
  235.          ;;
  236.       esac
  237.     else
  238.       $KEY $SEP $VALUE
  239.       NEXT_LINE=no-go
  240.       WAS_RUN=1
  241.     fi
  242.   done
  243. }
  244.  
  245. exit 0
  246.